#pragma once
#include "Container.h"


class DLL_EXP CGridContainer :
	public CContainerWidget
{
public:
	CGridContainer(void);
	virtual ~CGridContainer(void);
	
	int m_nRow;
	int m_nColumn;
	int m_nItemWidth;
	int m_nItemHeight;
	int m_nMaxRow;
	int m_nItemXOffset;
	int m_nItemYOffset;


	virtual bool SetGridProperty(int nColumns, int nRows, int nItemWidth,int nItemHeight)
	{
			m_nColumn = nColumns;
			m_nItemWidth=nItemWidth;
			m_nItemHeight = nItemHeight;
			m_nRow=nRows;			
			WRect rcMe;
			GetRect(&rcMe);

			float w = rcMe.dx;
			float h = rcMe.dy;
			float iw = nItemWidth;
			float ih = nItemHeight;
			
			float xtotal = nColumns;
			float ytotal = nRows;

			if(xtotal*iw > w || ih*ytotal>h)
			{
				return false;
			}

			m_nItemXOffset = (w-iw*xtotal)/(xtotal+1);
			m_nItemYOffset = (h-ih*ytotal)/(ytotal+1);						
	}

	virtual void InsertItem(CWidget* widget,int x,int y)
	{
		WRect rc;
		rc.x=x*m_nItemXOffset+(x-1)*m_nItemWidth;
		rc.y=y*m_nItemYOffset+(y-1)*m_nItemHeight;

		rc.dx=m_nItemWidth;
		rc.dy=m_nItemHeight;
		widget->SetRect(&rc);
		InsertWidget(widget);
	}


	int FindWidget(CWidget* pWidget, int* x, int* y);

	int m_nChildWidgets;
};
